const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    
  },
  backto: function (e) {
    wx.navigateBack({})
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    let extConfig = wx.getExtConfigSync ? wx.getExtConfigSync() : {};
    const token = extConfig.appid;
    that.setData({
      token: token,
      shop_id: options.shop_id
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  formSubmit: function (e) {
    var that = this;
    var data = e.detail.value;
    data.openid = app.globalData.openid;
    data.shop_id = that.data.shop_id;
    wx.showLoading({
      title: '预约中..',
    })
    wx.request({
      url: 'https://www.58zltc.com/api.php/Shop/addYuyue?token=' + that.data.token,
      data: data,
      method: 'POST',
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      success: function (res) {
        wx.hideLoading();
        if (res.data.error) {
          wx.showToast({
            title: res.data.msg,
            icon: 'none',
            duration:1500
          })
        } else {
          wx.showToast({
            title: res.data.msg,
            icon: 'success',
            duration: 1500
          })
          setTimeout(function(){
            wx.navigateBack({})
          },1500)
        }
      }
    })
  }
})